﻿<!DOCTYPE html>

<!--安全分委会组织架构-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    
<div id="app" v-cloak>   
        <el-row>
            
            <el-col :span="24">
                <el-form label-position="right" ref="form" :inline="true" :model="formInline" class="demo-form-inline"
                    style="margin-bottom: 15px;">
                    <el-row>
                        <el-col class="head-tool">
                            
<div class="new_title fl"><strong><img src="/static/images/icon1.png" />安全分委会组织架构列表</strong></div>
<span>
    <btn :text="col.btnSelect" imgsrc="/static/images/search.png" linetype="3"
         @click="onSubmit"></btn>
    <btn :text="col.btnAdd" linetype="3" @click="UserInput('tj')"></btn>
    <btn-uploadfile-list url="/Api/ZB_OfficeSafety/Import" linetype="3"></btn-uploadfile-list>
    <btn-export-list url="/Api/ZB_SafetyUser/Export" :forminline="this.formInline" linetype="3"></btn-export-list>
    <btn-template-download tempname="安全分委会成员.xlsx"></btn-template-download>
    <btn :text="col.btnDelete" linetype="4" @click="onDelete"></btn>
</span>
                        </el-col>
                    </el-row>
                    <el-row class="popupW100">
                        <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input v-model="formInline.model.sysUser.name"
                                        :placeholder="OrganizationalStructureSafety.Name" size="mini">
                                        <template slot="prepend">
                                            {{OrganizationalStructureSafety.Name+mark.m}}
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>

                        <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                            <el-form-item>
                                <el-input size="mini">
                                    <template slot="prepend">
                                        {{OrganizationalStructureSafety.Department+mark.m}}
                                    </template>
                                    <treeselect v-model="formInline.model.Department"
                                                :options="department"
                                                :flat="true"
                                                :show-count="true"
                                                slot="suffix"
                                                style="line-height: 28px;"
                                                placeholder="请选择" />
                                </el-input>
                            </el-form-item>
                        </div>
                        </el-col>
                        <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input v-model="formInline.model.PhoneNumber"
                                        :placeholder="OrganizationalStructureSafety.PhoneNumber" size="mini">
                                        <template slot="prepend">
                                            {{OrganizationalStructureSafety.PhoneNumber+mark.m}}
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input v-model="formInline.model.ExtensionNumber"
                                        :placeholder="OrganizationalStructureSafety.ExtensionNumber" size="mini">
                                        <template slot="prepend">
                                            {{OrganizationalStructureSafety.ExtensionNumber+mark.m}}
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                    </el-row>
                </el-form>
                <el-col :span="4">
                    <div class="tree_lay">
                        <h4 class="title clearfix"><strong>组织架构</strong></h4>
                        <el-tree :data="TreeData" :props="defaultProps" @node-click="handleNodeClick">
                            <span slot-scope="scope">
                                <span>
                                    <i :class="scope.data.icon"></i>
                                    <template>
                                        <span v-if="scope.data.icon == 'tree-open'" style="color:#12489e">{{ scope.node.label }}</span>
                                        <span v-else-if="scope.data.icon == 'tree-close'"
                                            style="color: #12489e">{{ scope.node.label }}</span>
                                        <span v-else>{{ scope.node.label }}</span>
                                    </template>
                                </span>
                        </el-tree>
                    </div>
                </el-col>
                <el-col :span="20">
                <el-table ref="table" stripe :data="ListItem.tableData" :height="ListItem.tableHeight" border
                    @selection-change="handleSelectionChange" row-style="height:10px" style="width: 100%">
                    <el-table-column type="selection" align="center" width="55">
                    </el-table-column>
                    <el-table-column type="index" :label="col.SequenceNumber" :index="indexMethod" width="50"
                        show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="mark03" :label="OrganizationalStructureSafety.Name">
                    </el-table-column>
                    <el-table-column prop="mark01" :label="OrganizationalStructureSafety.Department">
                    </el-table-column>
                    <el-table-column prop="phoneNumber" :label="OrganizationalStructureSafety.PhoneNumber">
                    </el-table-column>
                    <el-table-column prop="extensionNumber" :label="OrganizationalStructureSafety.ExtensionNumber">
                    </el-table-column>
                    <el-table-column width="53" prop="update" :label="col.btnUpdate" fixed="right">
                        <template slot-scope="scope">
                            <button type="button" class="elst-bt-xg" @click=UserInput('xg',scope.row.id)>
                                <i class="el-icon-edit"></i>
                            </button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-row type="flex" justify="end">
                    <el-pagination ref="page" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="ListItem.currentPage" :page-sizes="ListItem.pagesizes"
                        :page-size="ListItem.pagesize" :layout="ListItem.layout" :total="ListItem.total">
                    </el-pagination>
                </el-row>
                </el-col>
            </el-col>
        </el-row>
        <el-dialog title="安全分委会组织架构" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%"
            height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (!v.pid) v.pid = guidEmpty;
                if (v.pid == pid) {
                    var obj = {};
                    obj.id = v.id + '';
                    obj.label = v.name + '';
                    obj.icon = 'tree-item';
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                        obj.icon = 'tree-open';
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    TreeData: [],
                    department: [],
                    mydata: treeOrganizationalStructureSafety,
                    defaultProps: {
                        children: 'children',
                        label: 'label'
                    },
                    RiskLevel: [],
                    ListItem: ListItem,
                    formInline: {
                        model: { sysUser: { name: '' }, ZBSafetyFrameWorkId: '',  Department: null, PhoneNumber: '', ExtensionNumber: '', TreeNode: '' },
                        offset: 0,
                        limit: 10
                    }
                }
            }, created: function () {
                var currApp = this;
                window.onresize = function () {
                    currApp.ListItem.tableHeight = window.innerHeight -
                        currApp.$refs.table.$el.offsetTop - 60;
                    if (currApp.ListItem.tableHeight < 112) {
                        currApp.ListItem.tableHeight = 112;
                    }
                }
            },
            mounted: function () {
             //   this.RiskLevel = getDicData('03');
                //初始化数据
                this.GetPageData(1);
                this.TreeData = this.GetAreaTreeData();
                this.Department = this.GetDepartment();
                //列表高度自适应
                tablehigh(this);
              //  this.TreeData = fn(this.mydata, "0");
                //初始化tree高度
                //this.$nextTick(function () {
                //    this.TreeStyle.height = window.innerHeight -
                //        this.$refs.table.$el.offsetTop - 60 + "px";
                //})
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },
                handleNodeClick: function (data) {
                 
                    if (!data.children) {
                        //this.$refs.tree.setCheckedKeys([]);
                        //this.$refs.tree.setCheckedKeys([data.id]);
                        this.formInline.model.ZBSafetyFrameWorkId = data.id
                        onSubmit(this);
                    } else {
                     
                        //this.$refs.tree.setCheckedKeys([]);
                        //this.$refs.tree.setCheckedKeys([data.id]);
                        this.formInline.model.ZBSafetyFrameWorkId = data.id
                        if (data.icon == "tree-open") {
                            data.icon = "tree-close"
                        } else (
                            data.icon = "tree-open"
                        )
                        onSubmit(this);
                    }
                 
                    this.formInline.model.ZBSafetyFrameWorkId = this.$refs.tree.getCheckedKeys()
                    onSubmit(this);
                },
                closeDialog: function () { closeDialog(this); },
                //删除方法
                onDelete: function () { onDelete(this, '/api/ZB_SafetyUser/DeleteMuti'); },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //Dialog展示
                UserInput: function (val, id) { DialogShow(this, val, "OrganizationalStructureSafetyInput.html", id); },
                //获取分页数据
                GetPageData: function (currentIndex) {
                
                    //注意：后台约束空值为null  但是Tree id =null时有bug体现在setCheckedKeys 所以只能在扁平化上处理为guidempty，在传给后台前设置为空数组
                    if (this.formInline.model.ZBSafetyFrameWorkId == guidEmpty)
                    {
                        this.formInline.model.ZBSafetyFrameWorkId = null;
                    }
                    GetPageData(this, currentIndex, '/api/ZB_SafetyUser/GetList')
                },
                //查询方法
                onSubmit: function () { onSubmit(this); },
                //pagesize改变 触发方法
                handleSizeChange: function (val) { handleSizeChange(this, val); },
                //跳页触发方法
                handleCurrentChange: function (val) { handleCurrentChange(this, val); },
                GetAreaTreeData: function () {
                    var mythis = this;
                    var typeData;
                    myAjax("get", mythis, '/api/ZB_SafetyFrameWork/BasisType', null, function (response) {
                        var dataSource = response.data;
                        var data = MenuHelper(dataSource, guidEmpty);
                        data.unshift({ id: guidEmpty, label: '全部', Id: guidEmpty })//初始化无父级的选项
                        typeData = data;
                    }, false);
                    return typeData;
                },
                //初始化部门下拉树
                GetDepartment: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: '' }, offset: 0, limit: 999 }, function (response) {
                        mythis.department = menuHelperX(response.data.pageData, guidEmpty)
                    }, false);
                },
            }
        });
        //下拉树数据格式化
        function menuHelperX(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelperX(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>
</html>
